package com.farmer.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmer.pojo.Projectapply;
import com.farmer.service.ProjectapplyService;
import com.farmer.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("projectapply")
@CrossOrigin
public class ProjectApplyController {
    @Autowired
    private ProjectapplyService projectapplyService;

    @PostMapping("add")
    public Result add(@RequestHeader String token, @RequestBody Projectapply projectapply) {
        Result result =projectapplyService.add(token,projectapply);
        return result;
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        Result result = projectapplyService.delete(id);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Projectapply projectapply) {
        Result result = projectapplyService.update(projectapply);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = projectapplyService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
        Result result = projectapplyService.getAll();
        return result;
    }

    /*
     * 根据标题模糊查询*/
    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String status){
        Result result = projectapplyService.getByTitleLike(status);
        return result;
    }

    @PostMapping("uploadFile")
    public  Result uploadFile(@RequestParam Integer id, @RequestBody MultipartFile file){
        Result result = projectapplyService.uploadFile(id,file);
        return result;
    }

   @GetMapping("page")
   public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                   @RequestParam(defaultValue = "10") Integer pageSize) {
    Result result=projectapplyService.page(pageNum,pageSize);
    return result;
}
    @GetMapping("getProjectapplyListByToken")
    public Result getProjectapplyListByToken(@RequestHeader String token){
        Result result = projectapplyService.getProjectapplyListByToken(token);
        return result;
    }
}
